package com.websql.yousql.service.impl;


import com.websql.yousql.annotation.OperationLog;
import com.websql.yousql.annotation.operationLog.OperationType;
import com.websql.yousql.config.dataSource.RoutingDataSourceContext;
import com.websql.yousql.dao.DBDao;
import com.websql.yousql.service.DBService;
import com.websql.yousql.entity.Database;
import com.websql.yousql.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
public class DBServiceImpl implements DBService {

    @Autowired
    private DBDao dbDao;
    public static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    @Override
    public List<Database> getAllDB() {
        RoutingDataSourceContext.setDataSourceRoutingKey("queryDB");
        return dbDao.getAllDB();
    }

    @OperationLog(content="获取所有用户",action = OperationType.SELECT,table = "user")
    @Override
    public List<User> getAllUser(String useDatabase) {
        RoutingDataSourceContext.setDataSourceRoutingKey(useDatabase);
        return dbDao.getAllUser();
    }
}
